﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MsgSender.AppSetting
{
    /// <summary>
    /// 配置信息
    /// </summary>
    public static class AppSettings
    {
        private static string[] _matchClassName = null;
        private static string[] _filterCaption = null;
        private static int _intrSearchTime = -1;
        private static int _msgCycleTime = -1;
        private static List<string> _sendTextList = null;
        private static string _db = null;

        public enum EMSendHotKey { CtrlEnter = 1, Enter }



        /// <summary>
        /// 匹配类名
        /// </summary>
        public static string[] matchClassName
        {
            get
            {
                if (_matchClassName == null)
                {
                    string matchWindowsClassNames = System.Configuration.ConfigurationManager.AppSettings["matchClassNames"];
                    _matchClassName = matchWindowsClassNames.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                };
                return _matchClassName;
            }
        }
        
        /// <summary>
        /// 过滤的标题
        /// </summary>
        public static string[] filterCaption
        {
            get
            {
                if (_filterCaption == null)
                {
                    string filterCaptions = System.Configuration.ConfigurationManager.AppSettings["filterCaption"];
                    _filterCaption = filterCaptions.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                };
                return _filterCaption;
            }
        }

        /// <summary>
        /// 处理窗口周期，默认5秒
        /// </summary>
        public static int intrSearchTime
        {
            get
            {
                if (_intrSearchTime == -1)
                {
                    string strSearchTime = System.Configuration.ConfigurationManager.AppSettings["intrSearchTime"];
                    int.TryParse(strSearchTime, out _intrSearchTime);
                    if (_intrSearchTime <= 0)
                        _intrSearchTime = 5;
                }
                return _intrSearchTime;
            }
            set { _intrSearchTime = value; }
        }

        /// <summary>
        /// 消息发送周期 默认48h
        /// </summary>
        public static int msgCycleTime
        {
            get
            {
                if (_msgCycleTime == -1)
                {
                    string strMsgCycleTime = System.Configuration.ConfigurationManager.AppSettings["msgCycleTime"];
                    int.TryParse(strMsgCycleTime, out _intrSearchTime);
                    if (_msgCycleTime <= 0)
                        _msgCycleTime = 48;
                }
                return _msgCycleTime;
            }
            set { _msgCycleTime = value; }
        }

        /// <summary>
        /// 发送的文字列表
        /// </summary>
        public static List<string> sendTextList
        {
            get
            {
                if (_sendTextList == null)
                {
                    string xmlFile = System.Configuration.ConfigurationManager.AppSettings["userSettings"];
                    CXmlDocument.CXmlDocument xml = new CXmlDocument.CXmlDocument(AppDomain.CurrentDomain.BaseDirectory+xmlFile);
                    
                    _sendTextList = xml.GetNodesValueList("/root/senderTextList/senderText");
                }
                return _sendTextList;
            }
        }

        /// <summary>
        /// 消息发送热键
        /// </summary>
        public static EMSendHotKey sendHotKey
        {
            get
            {
                string strSendHotKey = System.Configuration.ConfigurationManager.AppSettings["SendHotKey"];
                switch (strSendHotKey)
                {
                    case "1":
                        return EMSendHotKey.CtrlEnter;
                    case "2":
                    default:
                        return EMSendHotKey.Enter;
                }
            }
        }

        /// <summary>
        /// 数据库位置
        /// </summary>
        public static string DBConnnectString
        {
            get
            {
                if (_db == null)
                    _db = System.Configuration.ConfigurationManager.AppSettings["db"];
                return _db;
            }
            set { _db = value; }
        }

    }
}
